# _*_ coding:utf-8 _*_
# @Time : 2023/5/25 17:57
# @Author : wsl
# @File : day05_demo
# @Project : python  xpath解析 安装lxmp库 E:\python\Scripts
import urllib.request
import urllib.error
from lxml import etree

url = 'http://www.baidu.com/'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0'
}

request = urllib.request.Request(url=url, headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')

# 解析服务器响应文件
tree = etree.HTML(content)

# 获取指定的数据 返回类型是列表
result = tree.xpath('//input[@id="su"]/@value')[0]
print(result)
